//
//  SDChooseGameView.m
//  Sudoku
//
//  Created by wxlan on 16/6/16.
//  Copyright © 2016年 wxlan. All rights reserved.
//

#import "SDChooseGameView.h"

@implementation SDChooseGameView

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/
- (instancetype)initWithWidth:(CGFloat)width
{
    if (self = [super init]) {
        [self setupWithWidth:width];
    }
    return self;
}
- (void)setupWithWidth:(CGFloat)width
{
    NSInteger rowCount = 3;
    NSInteger numCount = 9;
    CGFloat checkWidth = width/rowCount;
    for (int i = 0; i < numCount; i++) {
        UIButton *button = [[UIButton alloc] init];
        button.layer.borderWidth = 1;
        button.layer.borderColor = [UIColor blackColor].CGColor;
        [self addSubview:button];
        [button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [button setTitle:[NSString stringWithFormat:@"%d",i+1] forState:UIControlStateNormal];
        [button setBackgroundImage:[UIImage imageWithColor:[UIColor orangeColor] size:CGSizeMake(checkWidth, checkWidth)] forState:UIControlStateSelected];
        
        NSInteger row = i/rowCount;
        NSInteger column = i%rowCount;
        
        [button mas_makeConstraints:^(MASConstraintMaker *make) {
            make.width.height.equalTo(@(checkWidth));
            make.left.equalTo(@(column * checkWidth) );
//            make.height.equalTo(@(checkWidth));
            make.top.equalTo(@(row * checkWidth));
        }];
        
    }

}
@end
